import { ElMessage } from 'element-plus';
import reqest from '../utils/request';

// 获取图形验证码
export const getCaptcha = () => {
  return reqest({
    method: 'get',
    url: '/api/captcha',
    // 设置响应类型为Bolb对象
    responseType: 'blob',
    headers: {
      'Accept': 'image/*'
    }
  });
};

// 登录请求api
export const login = (loginData) => {
  return reqest({
    url: '/auth/login',
    method: 'post',
    // headers: {
    //   withCredentials: true
    // },
    data: {
      identifier: loginData.identifier,
      password: loginData.password,
      captcha: loginData.captcha

    }
  }).then(res => {
    if (res.status === 200) {
      // 存储token
      sessionStorage.setItem('token', res.data.data)

    }
    return res
  })
}


// 获取用户信息
export const getUserInfo = () => {
  return reqest({
    method: 'get',
    url: '/user/show',
    headers: {
      'Authorization': sessionStorage.getItem('token')
    }
  })
}


// 注册请求api
export const register = (registerData) => {
  return reqest({
    url: '/auth/register',
    method: 'post',
    data: {
      identifier: registerData.identifier,
      password: registerData.password,
      repassword: registerData.repassword
    }
  })
}


//请求获取用户地址
export const getUserAddress = () => {
  return reqest({
    method: 'get',
    url: '/address/list',

  })
}
